#include "typedef.h"


StackPointer arch_build_stack_frame(StackPointer sp_top, address pc, object args)
{
    word *top = (word *)(sp_top);
    *top-- = (word)pc;   // pc
    *top-- = 0x04;        // x04  tp
    *top-- = 0x03;        // x03  gp
    *top-- = 0x01;        // x01  ra

    *top-- = 0x1f;        // x31  t6
    *top-- = 0x1e;        // x30  t5
    *top-- = 0x1d;        // x29  t4
    *top-- = 0x1c;        // x28  t3
    *top-- = 0x07;        // x07  t2
    *top-- = 0x06;        // x06  t1
    *top-- = 0x05;        // x05  t0

    *top-- = 0x1b;        // x27  s11
    *top-- = 0x1a;        // x26  s10
    *top-- = 0x19;        // x25  s9
    *top-- = 0x18;        // x24  s8
    *top-- = 0x17;        // x23  s7
    *top-- = 0x16;        // x22  s6
    *top-- = 0x15;        // x21  s5
    *top-- = 0x14;        // x20  s4
    *top-- = 0x13;        // x19  s3
    *top-- = 0x12;        // x18  s2
    *top-- = 0x09;        // x09  s1
    *top-- = 0x08;        // x08  s0/fp

    *top-- = 0x11;        // x17  a7
    *top-- = 0x10;        // x16  a6
    *top-- = 0x0f;        // x15  a5
    *top-- = 0x0e;        // x14  a4
    *top-- = 0x0d;        // x13  a3
    *top-- = 0x0c;        // x12  a2
    *top-- = 0x0b;        // x11  a1
    *top-- = (word)args;        // x10  a0 trial_task_ctrl(a0)

    *top = 0x1;          // indicate full stack
    return top;
}
